{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import json \n",
    "from pprint import pprint\n",
    "from llm_handler import LLMHandler\n",
    "from config import FILE_PATHS\n",
    "from dotenv import load_dotenv\n",
    "\n",
    "load_dotenv(\"../.env\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "domain = \"telecom\"\n",
    "category = \"adaptive_tool_use\"\n",
    "\n",
    "persona_path = FILE_PATHS[\"personas\"].format(domain=domain)\n",
    "scenario_path = FILE_PATHS[\"scenarios\"].format(domain=domain, category=category)\n",
    "tool_path = FILE_PATHS[\"tools\"].format(domain=domain)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = \"gpt-4.1-mini-2025-04-14\"\n",
    "model_name = \"moonshotai/Kimi-K2-Thinking\"\n",
    "\n",
    "with open(scenario_path, \"r\") as f:\n",
    "    scenarios = json.load(f)\n",
    "    \n",
    "with open(tool_path, \"r\") as f:\n",
    "    tools = json.load(f)\n",
    "\n",
    "#delete response_schema key from tool and keep rest of the keys\n",
    "for tool in tools:\n",
    "    tool.pop(\"response_schema\", None)\n",
    "\n",
    "llm = LLMHandler().get_llm(model_name=model_name, tools=tools)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'Query: What is the balance of my account with the ids 123 and 234'\n",
      "\n",
      "Model Name: gpt-4.1-mini-2025-04-14\n",
      "\n",
      "Response Content:\n",
      "''\n",
      "\n",
      "Tool Calls:\n",
      "[{'args': {'account_number': '123'},\n",
      "  'id': 'call_jIUI8OwE0NU8xtEM3yuR0pn3',\n",
      "  'name': 'check_account_balance',\n",
      "  'type': 'tool_call'},\n",
      " {'args': {'account_number': '234'},\n",
      "  'id': 'call_Kz1gKa9vKmXNF3TM0FR4916e',\n",
      "  'name': 'check_account_balance',\n",
      "  'type': 'tool_call'}]\n",
      "\n",
      "Token Usage: input_tokens=3832, output_tokens=48\n"
     ]
    }
   ],
   "source": [
    "# call the llm with the tools\n",
    "system_prompt = \"\"\"\n",
    "You are a helpful assistant that can use the tools given to help the user. You can use multiple tools to answer the user's query. Generate multiple tool calls a time if needed.\n",
    "\"\"\"\n",
    "\n",
    "query = scenarios[0][\"first_message\"] \n",
    "query = \"What is the balance of my account with the ids 123 and 234\"\n",
    "# query = \"i want to check all the credit transactions for my account with the id 1234567890\"\n",
    "# query = \"I am earning 1000000 per year. I need a home loan of 100000 for 1 year\"\n",
    "\n",
    "pprint(f\"Query: {query}\")\n",
    "messages = [\n",
    "    {\"role\": \"system\", \"content\": system_prompt},\n",
    "    {\"role\": \"user\", \"content\": query},\n",
    "]\n",
    "\n",
    "response = llm.invoke(messages)\n",
    "\n",
    "print(\"\\nModel Name:\", model_name)\n",
    "print(\"\\nResponse Content:\")\n",
    "pprint(response.content)\n",
    "print(\"\\nTool Calls:\")\n",
    "pprint(response.tool_calls)\n",
    "input_tokens, output_tokens = LLMHandler.get_token_usage_info(response)\n",
    "print(f\"\\nToken Usage: input_tokens={input_tokens}, output_tokens={output_tokens}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python (al)",
   "language": "python",
   "name": "al"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
